/** @file
Acpi table platform header file.

Copyright (C) 2023, Phytium Technology Co Ltd. All rights reserved.<BR>

SPDX-License-Identifier: BSD-2-Clause-Patent

**/

#ifndef ACPI_PLATFORM_H_
#define ACPI_PLATFORM_H_

#include <IndustryStandard/Acpi.h>
/**
 Token[15:8] Socket
 Token[0:7]  Type
**/

/** This macro returns the Type from the Token.

  @param [in] Token A unique token for identifying the requested object.

  @retval Returns the Type corresponding to the Token.
**/

#define GET_TOKEN_TYPE(Token)      ((Token) & 0xFF)

/** This macro returns the Soket ID from the Token.

  @param [in] Token A unique token for identifying the requested object.

  @retval Returns the Socket ID corresponding to the Token.
**/
#define GET_TOKEN_SOCKETID(Token)  ((Token >> 8) & 0xFF)

/** The number of CPUs
*/
#define PLAT_CPU_COUNT              128

/** The number of ACPI tables to install
*/
#define PLAT_ACPI_TABLE_COUNT       7

/** The number of Its Nodes
*/
#define PLAT_ITS_COUNT              32

/** The number of Pci Nodes
*/
#define PLAT_PCI_COUNT              8

/** The number of memory affinity strunct
*/
#define PLAT_MEMORY_AFFINITY_COUNT  24

#define PHYTIUM_SYSTEM_TIMER_BASE_ADDRESS   0xFFFFFFFFFFFFFFFF
#define PHYTIUM_CNT_READ_BASE_ADDRESS       0xFFFFFFFFFFFFFFFF

#define GTDT_TIMER_EDGE_TRIGGERED   \
          EFI_ACPI_6_3_GTDT_TIMER_FLAG_TIMER_INTERRUPT_MODE
#define GTDT_TIMER_LEVEL_TRIGGERED  0
#define GTDT_TIMER_ACTIVE_LOW       \
          EFI_ACPI_6_3_GTDT_TIMER_FLAG_TIMER_INTERRUPT_POLARITY
#define GTDT_TIMER_ACTIVE_HIGH      0
#define GTDT_TIMER_SAVE_CONTEXT     \
          EFI_ACPI_6_3_GTDT_TIMER_FLAG_ALWAYS_ON_CAPABILITY
#define GTDT_TIMER_LOSE_CONTEXT     0

#define PHYTIUM_GTDT_GTIMER_FLAGS     (GTDT_TIMER_ACTIVE_LOW   | \
                                       GTDT_TIMER_LEVEL_TRIGGERED)

// Watchdog
#define SBSA_WATCHDOG_EDGE_TRIGGERED   \
          EFI_ACPI_6_3_GTDT_SBSA_GENERIC_WATCHDOG_FLAG_TIMER_INTERRUPT_MODE
#define SBSA_WATCHDOG_LEVEL_TRIGGERED  0
#define SBSA_WATCHDOG_ACTIVE_LOW       \
          EFI_ACPI_6_3_GTDT_SBSA_GENERIC_WATCHDOG_FLAG_TIMER_INTERRUPT_POLARITY
#define SBSA_WATCHDOG_ACTIVE_HIGH      0
#define SBSA_WATCHDOG_SECURE           \
          EFI_ACPI_6_3_GTDT_SBSA_GENERIC_WATCHDOG_FLAG_SECURE_TIMER
#define SBSA_WATCHDOG_NON_SECURE       0

#define PHYTIUM_SBSA_WATCHDOG_FLAGS       (SBSA_WATCHDOG_NON_SECURE    | \
                                          SBSA_WATCHDOG_ACTIVE_HIGH | \
                                          SBSA_WATCHDOG_EDGE_TRIGGERED)

#define PHYTIUM_IO_BASE_MASK     0xfffffff
#define PHYTIUM_MEM32_BASE_MASK  0xffffffff
#define PHYTIUM_MEM64_BASE_MASK  0x7ffffffffff
#define SOCKET_ADDRESS_OFFSEST   0x100000000000  //16T

#define PCI_ROOTPORT_COUNT       12
#define PCI_PRT_ENTRY_COUNT      (PCI_ROOTPORT_COUNT * 4)

#define PMU_INTERRUPT                    0x17
#define GIC_VIRTUAL_INTERRUPT            0x19

#define DEBUG_SERIAL_INTERRUPT           48

#define CPU_COUNT                16

#define ITS_COUNT                4
#define ITS_CONTROL_BASE         0x22040000
#define ITS_CONTROL_OFFSET       0x20000

//
// ACPI table information used to initialize tables.
//
#define EFI_ACPI_PHYTIUM_OEM_ID           'P','H','Y','L','T','D'                       // OEMID 6 bytes long
#define EFI_ACPI_PHYTIUM_OEM_REVISION     0x00010000
#define EFI_ACPI_PHYTIUM_CREATOR_ID       SIGNATURE_32('P','H','Y','T')
#define EFI_ACPI_PHYTIUM_CREATOR_REVISION 0x00010000

// A macro to initialise the common header part of EFI ACPI tables as defined by
// EFI_ACPI_DESCRIPTION_HEADER structure.
#define PHYTIUM_ACPI_HEADER(Signature, Type, TableId, Revision) {     \
    Signature,                          /* UINT32  Signature */       \
    sizeof (Type),                      /* UINT32  Length */          \
    Revision,                           /* UINT8   Revision */        \
    0,                                  /* UINT8   Checksum */        \
    { EFI_ACPI_PHYTIUM_OEM_ID },        /* UINT8   OemId[6] */        \
    TableId,                            /* UINT64  OemTableId */      \
    EFI_ACPI_PHYTIUM_OEM_REVISION,      /* UINT32  OemRevision */     \
    EFI_ACPI_PHYTIUM_CREATOR_ID,        /* UINT32  CreatorId */       \
    EFI_ACPI_PHYTIUM_CREATOR_REVISION   /* UINT32  CreatorRevision */ \
  }


#endif // PLATFORM_H__

